package com.lianwei.controller;

import com.lianwei.pojo.User;
import com.lianwei.pojo.request.UserLoginRequest;
import com.lianwei.pojo.request.UserRegisterRequest;
import com.lianwei.service.UserService;
import com.lianwei.util.JsonData;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

import java.util.List;
import java.util.Map;

@Api(tags = "用户模块")
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    UserService userService;

    @ApiOperation("用户登录")
    @PostMapping("/login")
    public JsonData login(@RequestBody UserLoginRequest userLoginRequest) {
        return userService.login(userLoginRequest);

    }

    @ApiOperation("用户注册")
    @PostMapping("/register")
    public JsonData register(@RequestBody UserRegisterRequest userRegisterRequest) {
        return userService.register(userRegisterRequest);
    }

    @ApiOperation("用户禁用")
    @GetMapping("/disable/{id}")
    public void disable(@PathVariable("id") int id){
        userService.disable(id);
    }
    @ApiOperation("用户启用")
    @GetMapping("/enable/{id}")
    public void enable(@PathVariable("id") int id){
        userService.enable(id);

    }
    @ApiOperation(("用户列表展示"))
    @GetMapping("/list")
    public List<User> userList(){
        List<User> userList = userService.queryList();
        return userList;
    }
    @ApiOperation("根据用户名查询")
    @GetMapping("/queryByName")
    public List<User> userListByName(@RequestParam("name") String name){
        List<User> userList = userService.queryListByName(name);
        return userList;
    }


}
